(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('underscore')) :
  typeof define === 'function' && define.amd ? define(['underscore'], factory) :
  global.validate = factory(_);
}(this, function (_) { 'use strict';

  function defaultCheck(condition, val) {
    switch(condition) {
      case 'required':
        return (val && val !== '' ? true : false);
      default:
        break;
    }
    return true;
  }

  var moduleName = function(options) {
    for (var param in options) {
      var val = options[param].val;
      var rules = options[param].rules;
      if (!rules) {
        continue;
      }

      for (var i = 0; i < rules.length; i++) {
        if (_.isString(rules[i].t)) {
          if (defaultCheck(rules[i].t, val)) {
            if (rules[i].s) {
              rules[i].s(val);
            }
            continue;
          } else {
            if (rules[i].f) {
              rules[i].f(val);
            }
            return false;
          }
        } else if (_.isFunction(rules[i].t)) {
          if (rules[i].t(val)) {
            if (rules[i].s) {
              rules[i].s(val);
            }
            continue;
          } else {
            if (rules[i].f) {
              rules[i].f(val);
            }
            return false;
          }
        }
      }
    }
    return true;
  }
  return moduleName

}))
